#include <stdio.h>
#include <math.h>

int calc(int number) {
    if (number < 10) {
        return number;
    } else {
        int num = 0;
        for (int i = 0; i < 6; i++) {
            num += number % 10;
            number /= 10;
        }
        return calc(num);
    }
}

int main(void) {
    int run = 1;
    while (run) {
        int c, len = 0, result = 0;
        while (c = getchar(), 1) {
            if (c == '\n' || c == EOF) {
                if (c == EOF || (len == 1 && result == 0)) {
                    // Bye
                    run = 0;
                }
                break;
            } else if (c >= '0' && c <= '9') {
                result += c - '0';
                len++;
            }
        }
        if (run) {
            printf("%d\n", calc(result));
        }
    }
    return 0;
}
